package com.ljsw.fragment;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ljsw.activity.R;
import com.ljsw.application.App;
import com.ljsw.dialog.DeleteDialog;
import com.ljsw.dialog.LoginDialog;
import com.ljsw.util.DialogManager;

/**
 * 我的任务 库管(押运)交接指纹验证
 * 作者: 石锚
 * 版本: 1.0
 * 日期: 2015-10-19
 */
public class FingerCheckFragment extends BaseFragment{
	private TextView kgjiaojie,//库管交接
	 				 qfyjiaojie,//清分员交接
	 				 text_tyep,//指纹提示信息上部分
	 				 text_tyepxia;////指纹提示信息下部分
	private View view;
	private ViewPager vpager;
	private List<Fragment> listViews;//指纹验证界面列表
	private int currIndex=0;//当前选项卡编号
	private KuguanFragment kuguanfrag;//库管员指纹验证
	private QingfyFragment qfyfrag;//清分员指纹验证
	private Bundle bundle;
	private String cid;//车牌号
	private String paigongdan;//派工单
	private App app; //全局变量
	private Handler handler;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.fragment_jiaojie, container, false);
		app = (App) getActivity().getApplication(); 
		app.back ="go";//处理返回键的标识
		initView();
		return view;
	}
	
	@Override
	public void onStart() {
		super.onStart();
	}
	/**
	 * 控件初始化
	 */
	public void initView(){
		kgjiaojie = (TextView) view.findViewById(R.id.kgjiaojie);//库管交接
	    qfyjiaojie = (TextView) view.findViewById(R.id.qfyjiaojie);//清分员交接
	    kgjiaojie.setOnClickListener(new SelectClickListener(0));
	    qfyjiaojie.setOnClickListener(new SelectClickListener(1));
	    vpager=(ViewPager)view.findViewById(R.id.vpager_fragment);    
	    //初始化选项卡内容区
	    listViews=new ArrayList<Fragment>();
	    //添加View
	    kuguanfrag = new KuguanFragment();
	    qfyfrag = new QingfyFragment();
	    bundle = getArguments();
	    if(bundle!=null){
	    	cid = bundle.getString("cid");//车牌号
	    	//把车牌号同时传给子布局
	    	bundle.putString("cid", cid);
	    	bundle.putSerializable("paigongdan", bundle.getSerializable("list"));
	    	bundle.putSerializable("paigongdan", bundle.getSerializable("box"));
	    	kuguanfrag.setArguments(bundle);
	    	qfyfrag.setArguments(bundle);
	    }
	    listViews.add(kuguanfrag);//添加库管验证子布局
	    //listViews.add(qfyfrag);//添加清分验证子布局
	    vpager.setAdapter(new FingerCheckPagerAdapter(getChildFragmentManager(),listViews));
	    vpager.setCurrentItem(0);//设置当前子布局
	    vpager.setOnPageChangeListener(new MyOnPageChangeListener());//切换子布局事件
	}	
	
	/**
	 * 选项卡单击事件监听
	 */
	public class SelectClickListener implements OnClickListener{
		private int index=0;
		
		public SelectClickListener(int i) {
			index=i;
		}
		public void onClick(View v) {
			vpager.setCurrentItem(index);
		}
	}
	/**
	 * Viewpager适配器,实现各选项卡页面的装入和卸载
	 */
	public class FingerCheckPagerAdapter extends FragmentPagerAdapter{
		public List<Fragment> mListViews;
		
		public FingerCheckPagerAdapter(FragmentManager fm, List<Fragment> mListViews) {
			super(fm);
			this.mListViews = mListViews;
		}

		@Override
		public Fragment getItem(int position) {
			return mListViews.get(position);
		}
		@Override
		public int getCount() {
			return mListViews.size();
		}
	}
	
	public class MyOnPageChangeListener implements OnPageChangeListener{
	
		public void onPageScrollStateChanged(int arg0) {
			
		}
	
		public void onPageScrolled(int arg0, float arg1, int arg2) {
			
		}
	
		public void onPageSelected(int index) {
			switch (index) {
			case 0://我的任务(回库交接状态视图) 库管交接
				qfyjiaojie.setBackgroundResource(R.drawable.button_blue1_u628);
				kgjiaojie.setBackgroundResource(R.drawable.button_blue1_u628_mousedown);
				break;
			case 1://我的任务(回库交接状态视图) 清分员交接
				kgjiaojie.setBackgroundResource(R.drawable.button_blue1_u628);
				qfyjiaojie.setBackgroundResource(R.drawable.button_blue1_u628_mousedown);
				break;	
			}
			currIndex=index;
		}	
	}
}
